﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FSY.API.Utilities;
using FSY.Components.Entities;

namespace FSY.Web.Admin.Authentication
{
    public partial class Login : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                Fsy_User user = Fsy_UserController.CheckUser(txtUserName.Text, txtPassword.Text);
                if (user != null)
                {
                    //Login thanh cong
                    Session["UserID"] = user.UserID;
                    Session["UserName"] = user.UserName;
                    if (user.IsSuperUser)
                        Session["IsSuperAdmin"] = "true";                    
                    Response.Redirect("Default.aspx");
                }
                else
                {
                    //User khong ton tai trong he thong
                    LabelMessages.Text = "Đăng nhập không đúng";
                }
            }
            catch(NullReferenceException ex)
            {
                FsyLoggerHelper.WriteError("FSY.Web.Admin.Authentication.Login ----btnLogin_Click  -----" + ex.Message);
            }
        }

        protected void lbtnRegister_Click(object sender, EventArgs e)
        {
            Session["register"] = "1";
            Response.Redirect("Login.aspx");
        }
    }
}